import sys
import numpy as np

vec = sys.argv[1]


def winner(vec):
    M = np.mat(vec).reshape((15, 15))
    mat = np.zeros((19, 19))
    mat[0:15, 0:15] = M
    ks = list()
    kernel = np.zeros((5, 5))
    kernel[:, 0] = 1
    ks.append(kernel)
    kernel = np.zeros((5, 5))
    kernel[0, :] = 1
    ks.append(kernel)
    ks.append(np.eye(5))
    ks.append(np.rot90(np.eye(5)))
    for i in range(0, 15):
        for j in range(0, 15):
            Mat = mat[i:i + 5, j:j + 5]
            for k in ks:
                sum = np.sum(k * Mat)
                # 黑胜
                if sum == 5:
                    return 2
                # 白胜
                elif s == 35:
                    return 3

    # 继续
    if np.sum(mat) < 897:
        return 0
    # 和棋
    else:
        return 1


print(winner(M))
